/**
 * Collection class
 * for holding connection sessions.
 * This will send update requests and
 * do the talking to the server
 * for the player
 */
package user;

import java.io.IOException;
import java.net.Socket;

import database.SQL;

import networkcom.Opcode;
import networkcom.Packet;
import networkcom.PacketInputStream;
import networkcom.PacketOutputStream;

public class Session {
	private String public_key;
	private String private_key;
	private Socket sock;
	private PacketInputStream in;
	private PacketOutputStream out;
	private Player client;
	private int sid;
	private SQL sql;
	private int stat;
	
	public Session(Socket s, int id,int stats){
		this.sock = s;
		client = new Player(id);
		sid = id;
		stat = stats;
		try {
			in = new PacketInputStream(s.getInputStream());
			out = new PacketOutputStream(s.getOutputStream());
		} catch (IOException e) {}
		
		Thread t = new Thread(new Runnable(){
			public void run() {
				while(true){
					Packet p = in.readPacket();
					if(p!=null){
						handlePacket(p);
					}
				}
			}
			private void handlePacket(Packet p){
				int op = p.getOpcode();
				if(op == Opcode.CHAT){
					//Do chat message
				}else if(op == Opcode.MOVE_FORWARD){
					client.lastForward = p;
				}else if(op == Opcode.S_MOVE_FORWARD){
					
				}else if(op == Opcode.MOVE_BACKWARD){
					
				}else if(op == Opcode.S_MOVE_BACKWARD){
					
				}else if(op == Opcode.MOVE_LEFT){
					
				}else if(op == Opcode.S_MOVE_LEFT){
					
				}else if(op == Opcode.MOVE_RIGHT){
					
				}else if(op == Opcode.S_MOVE_RIGHT){
					
				}else if(op == Opcode.ROTATE_LEFT){
					
				}else if(op == Opcode.S_ROTATE_LEFT){
					
				}else if(op == Opcode.ROTATE_RIGHT){
					
				}else if(op == Opcode.S_ROTATE_RIGHT){
					
				}else if(op == Opcode.FIRE_MAIN){
					
				}else if(op == Opcode.FIRE_WEAPON1){
					
				}else if(op == Opcode.FIRE_WEAPON2){
					
				}
			}
		});
		t.start();
	}
	
	public Session(Player c){
		client = c;
	}
	public void update(){
		
	}
	
	public int getID(){
		return sid;
	}
	
	public Player getPlayer(){
		return client;
	}
	

}
